package com.wsoft.portal.controller;

import com.wsoft.portal.query.module.*;
import com.wsoft.portal.service.IPortalModuleService;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 空间类型 前端控制器
 * @author Z001
 * @since 2024年12月27日 10:02:24
 */
@RestController
@Tag(name = "板块")
@RequestMapping("/portal/module")
public class PortalModuleController {

    @Resource
    private IPortalModuleService moduleService;

    @Operation(summary = "新增板块", description = "新增板块")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid ModuleInsertQuery query) {
        boolean b = moduleService.insertModule(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "修改板块", description = "修改板块")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid ModuleUpdateQuery query) {
        boolean b = moduleService.updateModule(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }


    @Operation(summary = "板块详情", description = "板块详情")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(moduleService.getModuleInfo(id));
    }


    @Operation(summary = "删除板块", description = "删除板块")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = moduleService.deleteModule(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }


    @Operation(summary = "修改板块宽高和XY轴", description = "修改板块宽高和XY轴")
    @PostMapping("/updateWhSort")
    public ResponseResult updateWhSort(@RequestBody @Valid List<ModuleWidthHeightListQuery> query) {
        boolean b = moduleService.updateWhSort(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }


}
